package main

import (
	"fmt"
	"ota/utils/cron"
	"time"
)

var index int
var c = cron.New(cron.WithLocation(time.Local), cron.WithSeconds(), cron.WithChain())

func timerCallBack(args ...interface{}) {

	var (
		entry = args[0].(*cron.Entry)
	)
	index = index + 1
	if index == 10 {
		c.Remove(entry.ID)
	}
	fmt.Println("timer Trigger:", entry, index)

}

func main() {
	c.Start()

	t := time.Now()
	spec := fmt.Sprintf("%v %v %v %v %v *", t.Second(), t.Minute(), t.Hour(), t.Day(), int(t.Month()))
	//spec := fmt.Sprintf("* * * * * *")

	fmt.Println(spec)
	fmt.Println(c.AddFunc(spec, timerCallBack, 1, "a", "b"))
	exit := make(chan bool)
	<-exit
}
